package com.ys.controller.web.bi;

import com.ys.service.bi.BiFinancialFundsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.ys.vo.R;


@Controller
@RequestMapping("/web/bi/finance")
public class WebBiFinanceController {
	private static final Logger logger = LoggerFactory.getLogger(WebBiFinanceController.class);

	public static Long MENU_ID = 10148L;

	@Autowired
	private BiFinancialFundsService biFinancialFundsService;

	/*
	 * 财务资金
	 */
	@GetMapping("/fund")
	public String fund(Model model, String loginName, String pass){
		return "bi/finance/fund";
	}

	/*
	 * 财务资金趋势
	 */
	@GetMapping("/trend")
	public String trend(Model model, String loginName, String pass){
		return "bi/finance/trend";
	}

	/**
	 * bi页面获取数据，根据类型
	 */
	@PostMapping("/getBiFinancialFundsJson")
	@ResponseBody
	public JSONObject getBiFinancialFundsJson(){
		JSONObject res = new JSONObject();
		try {
			res = biFinancialFundsService.getBiFinancialFundsJson();
			res.put("code",R.Code.SUCCESS.value);
		}catch (Exception e){
			logger.error("获取财务资金BI统计数据出错：",e.getMessage(),e);
			res.put("code",R.Code.FAILED.value);
			res.put("msg","获取财务资金BI数据失败，请稍后重试！");
		}
		return res;
	}

	/**
	 * bi财务资金趋势
	 */
	@PostMapping("/getBiFinancialTrend")
	@ResponseBody
	public JSONObject getBiFinancialTrend(){
		JSONObject res = new JSONObject();
		try {
			res = biFinancialFundsService.getBiFinancialTrend();
			res.put("code",R.Code.SUCCESS.value);
		}catch (Exception e){
			logger.error("获取财务资金BI趋势统计数据出错：",e.getMessage(),e);
			res.put("code",R.Code.FAILED.value);
			res.put("msg","获取财务资金BI趋势数据失败，请稍后重试！");
		}
		return res;
	}
}
